﻿@using AdverseEventReportSystem.Model
@{
    var ycFanKui = ViewBag.AdverseEventYcFanKui as AdverseEventYcFanKui;
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <link href="~/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/common.css" rel="stylesheet" type="text/css" />
    <script src="~/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="~/lib/ligerUI/js/ligerui.all.js"></script>
    <script src="~/Scripts/common.js"></script>
</head>
<body>
    <div style="margin:10px 0px;">
        <table class="gridtable">
            <tr>
                <td style="text-align:right; width:60px;">
                    转归：
                </td>
                <td>
                    <div style="float:left;">
                        <label for="zgType1">
                            <input type="radio" id="zgType1" name="zgType" value="0" @(ycFanKui.ZgType == 0 || ycFanKui.ID == 0 ? "checked" : "") />出院
                        </label>&nbsp;&nbsp;
                        <label for="zgType2">
                            <input type="radio" id="zgType2" name="zgType" value="1" @(ycFanKui.ZgType == 1 ? "checked" : "") />转科
                        </label>
                    </div>
                    <div id="divZgDepartmentCode" style="float:left;margin-left:10px;margin-top:5px;">
                        <input type="text" id="zgDepartmentCode" />
                    </div>
                    <div style="float:left;margin-left:10px;">
                        <div style="float:left;">日期：</div>
                        <div style=" float:left;margin-top:5px;">
                            <input type="text" id="txtZgDate" class="l-text" maxlength="10" value="@(ycFanKui.ZgDate)" />
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="text-align:right; width:60px;vertical-align: text-top; ">
                    预后：
                </td>
                <td>
                    <div style="float:left;">
                        <label for="yhType1">
                            <input type="radio" id="yhType1" name="yhType" value="0" @(ycFanKui.YhType == 0 || ycFanKui.ID == 0 ? "checked" : "") />愈合
                        </label>&nbsp;&nbsp;
                        <label for="yhType2">
                            <input type="radio" id="yhType2" name="yhType" value="1" @(ycFanKui.YhType == 1 ? "checked" : "") />好转
                        </label>&nbsp;&nbsp;
                        <label for="yhType3">
                            <input type="radio" id="yhType3" name="yhType" value="2" @(ycFanKui.YhType == 2 ? "checked" : "") />加重
                        </label>&nbsp;&nbsp;
                        <label for="yhType4">
                            <input type="radio" id="yhType4" name="yhType" value="3" @(ycFanKui.YhType == 3 ? "checked" : "") />无变化
                        </label>
                    </div>
                    <div id="divYhRemarks" style="clear:both; display:@((ycFanKui.YhType == 1 || ycFanKui.YhType == 2 )? "" : "none");">
                        <div style="width:350px;">
                            <textarea id="txtYhRemarks" rows="5" class="l-textarea" maxlength="500" style="padding:5px;width:100%;">@(ycFanKui.YhRemarks)</textarea>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center;padding-top:10px;">
                    <input id="btnSubmit" type="button" value="确定" class="l-button" onclick="save()" />&nbsp;&nbsp;&nbsp;
                    <input id="btnCancel" type="button" value="取消" class="l-button-cancel" onclick="closeDialog()" />
                </td>
            </tr>
            <tr></tr>
        </table>
        <input type="hidden" id="hdnEventId" value="@(ycFanKui.EventId)" />
    </div>
</body>
</html>
<script>
    $(function () {
        $("#txtZgDate").ligerDateEditor({
            showTime: true,
            format: "yyyy-MM-dd",
            width: 90,
            cancelable: false
        });

        $("#zgDepartmentCode").ligerComboBox({
            cancelable: false,
            width: 115,
            url: "/AdverseEvent/EditPressureSoreEvent/GetAllUnits?ram" + Math.random(),
            valueField: "DepartmentCode",
            textField: "DepartmentName",
            valueFieldID: 'hdnZgDepartmentCode',
            onSuccess: function (data) {
                $("#zgDepartmentCode").ligerComboBox().setValue(data[0].DepartmentCode);
                $('input[name="zgType"]:checked').click();
            }
        });

        $("input[name='zgType']").click(function () {
            if ($(this).val() == 1) {
                $("#divZgDepartmentCode").show();
            }
            else {
                $("#divZgDepartmentCode").hide();
            }
        });

        $("input[name='yhType']").click(function () {
            if ($(this).val() == 1 || $(this).val() == 2) {
                $("#divYhRemarks").show();
            }
            else {
                $("#divYhRemarks").hide();
            }
        });
    });

    function save() {
        var eventId = $("#hdnEventId").val();
        var zgType = $('input[name="zgType"]:checked').val();
        var zgDepartmentCode = "";
        var zgDepartmentName = "";
        if (zgType == 1) {
            zgDepartmentCode = $("#hdnZgDepartmentCode").val();
            zgDepartmentName = $("#zgDepartmentCode").ligerComboBox().getText();
        }
        var zgDate = $("#txtZgDate").val();
        var yhType = $('input[name="yhType"]:checked').val();
        var yhRemarks = "";
        if (yhType == 1 || yhType == 2) {
            yhRemarks = $("#txtYhRemarks").val();
        }
        var ycFanKuidata = {
            EventId: eventId,
            ZgType: zgType,
            ZgDepartmentCode: zgDepartmentCode,
            ZgDepartmentName: zgDepartmentName,
            ZgDate: zgDate,
            YhType: yhType,
            YhRemarks: yhRemarks
        };

        parent.$("#hdnYcFanKuiJson").val(JSON.stringify(ycFanKuidata));

        if (eventId > 0 && parent.$("#btn1").val() != "保存" && parent.$("#btn1").val() != "上报") {
            $.ajax({
                url: "/AdverseEvent/EditPressureSoreEvent/YcFanKuiSave",
                type: "post",
                data: {
                    ycFanKui: ycFanKuidata,
                    oldStatus: frameElement.dialog.get('data').oldStatus,
                },
                success: function (r) {
                    var r = $.parseJSON(r);
                    if (r.Result == 1) {
                        $.ligerDialog.success("反馈成功");
                        if (r.Body.Status == frameElement.dialog.get('data').oldStatus) {
                            parent.$("#txtYuHou").val(r.Body.YuHou);
                            parent.$("#txtZhuanGui").val(r.Body.ZhuanGui);
                            setTimeout(function () { closeDialog(); }, 1000);
                        }
                        else {
                            setTimeout(function () { parent.location.reload(); }, 1000);
                        }

                    }
                    else if (r.Result == 0) {
                        $.ligerDialog.error(r.Body);
                    }
                    else {
                        $.ligerDialog.error("程序错误");
                    }
                },
                error: function () {
                    $.ligerDialog.error("程序错误");
                }
            });
        }
        else {
            var zhuanGui = "";
            switch (zgType) {
                case "0":
                    zhuanGui += "出院 " + zgDate;
                    break;
                case "1":
                    zhuanGui += "转科 " + zgDepartmentName + " " + zgDate;
                    break;
            }
            var yuHou = "";
            switch (yhType) {
                case "0":
                    yuHou += "愈合";
                    break;
                case "1":
                    yuHou += "好转 " + yhRemarks;
                    break;
                case "2":
                    yuHou += "加重 " + yhRemarks;
                    break;
                case "3":
                    yuHou += "无变化";
                    break;
            }
            parent.$("#txtYuHou").val(yuHou);
            parent.$("#txtZhuanGui").val(zhuanGui);
            closeDialog();
        }
    }
</script>